#ifndef __LOCKGUARD_HPP__
#define __LOCKGUARD_HPP__
#include <pthread.h>


//RAII风格的加锁和解锁，定义一个对象自动加锁，对象销毁自动解锁
class LockGuard
{
public:
    LockGuard(pthread_mutex_t& mutex) : _mutex(mutex)
    {
        pthread_mutex_lock(&_mutex);
    }

    ~LockGuard()
    {
        pthread_mutex_unlock(&_mutex);
    }

private:
    pthread_mutex_t &_mutex;
};

#endif